package com.weimei.conversionTreasure.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;

import com.weimei.conversionTreasure.R;
import com.weimei.conversionTreasure.app.AppViewModelFactory;
import com.weimei.conversionTreasure.databinding.ActivityAddJxsBinding;
import com.weimei.conversionTreasure.http.entity.DealerDetailBean;
import com.weimei.conversionTreasure.utils.ValidateUtils;
import com.weimei.conversionTreasure.viewModel.AddJxsVM;
import com.weimei.conversionTreasure.viewModel.AddKhVM;

import me.goldze.mvvmhabit.base.BaseActivity;
import me.tatarka.bindingcollectionadapter2.BR;

public class AddJxsActivity extends BaseActivity<ActivityAddJxsBinding, AddJxsVM> {


    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_add_jxs;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    DealerDetailBean.DataDTO bean;

    @Override
    public void initParam() {
        super.initParam();
        bean = (DealerDetailBean.DataDTO) getIntent().getSerializableExtra("data");
    }

    @Override
    public void initData() {
        super.initData();
        if (ValidateUtils.isNotEmptyObjectOrString(bean)){
            viewModel.name.set(bean.getName());
            viewModel.phone.set(bean.getTelephone());
            viewModel.wechat.set(bean.getWeChat());
            viewModel.nots.set(bean.getNotes());
            viewModel.sid.set(bean.getId()+"");
            viewModel.title.set("编辑经销商");
        }else {
            viewModel.title.set("添加经销商");
        }
    }

    @Override
    public AddJxsVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, (ViewModelProvider.Factory) factory).get(AddJxsVM.class);
    }
}